package com.quick;

import com.quick.util.JSONUtil;
import com.quick.util.QuickTool;
import com.quick.util.User;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.lang.Nullable;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.quick.util.DateUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;

import javax.crypto.Cipher;
import javax.servlet.http.HttpServletRequest;

@Data
@Slf4j
@SuppressWarnings("unused")
public class Quick {
	
	private static final Logger logger = LoggerFactory.getLogger(Quick.class);

    private static String project = "quick-api";
    private static String version = "1.0.0";
    private static String author = "quick-api";
    private static String website = "https://github.com/quick-api/quick-api";
	private static String copyright = "Copyright © 2020-2021 quick-api. All rights reserved.";
    private static String license = "Apache License 2.0";
    private static String licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0";
    private Map<String, Object> develop = new HashMap<>();
    private static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();
    
    
    public static void main(String[] args) throws Exception {
    	int len = 12;
    	for (int i = 1; i <= len; i++) {
    		DecimalFormat df = new DecimalFormat("#.00");
			//System.out.println(".have-"+len+">*.col-"+i+"{width:"+String.format("%.8f", ((double)i/12)*100)+"%;}");
			
		}
    	//Quick.decrypt("/HM2zXSk9GvcnzD1PvNwij5buVA6hWBTqYQaIzfO/DiB8sfivQIg4ak6VzUU8xcM0SYQP/bgw0sq8dPaeUpB38rhXEZf9BzjT3TIdERLiLHYfUGjMeORE6q7IFRUtN2wyuaHTXH0/aNdK1WtcT4DLbUnnvnFsepHYWLXcGUlJQRYHmyV43VA7N240WPgi9wCULk/wUwF2BIYhtntiCkdcw==","kKmEdLp+b9rXuFH54MP8Kw==");
    	User user = null;
    	QuickTool.isNull(user);
    	System.out.println("");
    }
    public static String decrypt(String encryptedData, String privateKey) throws Exception {
        byte[] encryptedBytes = Base64.getDecoder().decode(encryptedData);

        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKey));
        KeyFactory keyFactory = KeyFactory.getInstance("SHA1");
        PrivateKey privateKeyObj = keyFactory.generatePrivate(keySpec);

        Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.DECRYPT_MODE, privateKeyObj);

        byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
        return new String(decryptedBytes, StandardCharsets.UTF_8);
    }
}
